package com.platform.hjt.base.interceptor;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * 拦截jsp请求
 * @author huangjt
 */
public class JspFilter implements Filter{

	protected Logger logger = Logger.getLogger(getClass());
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse rep,
			FilterChain filterChain) throws IOException, ServletException {
			
			HttpServletResponse response = (HttpServletResponse) rep;  
	        HttpServletRequest request = (HttpServletRequest) req;  
	        
	        logger.debug(req.getRemoteAddr() + "---" + "试图直接访问JSP页面");
	        
			response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);  	//301跳转
			response.setHeader("Location", request.getContextPath() + "/404.html");  
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
	}

}
